from django.contrib.gis.db import models
from django.utils.translation import ugettext_lazy as _

from duetopia.register.fields import ParsedDateField

class TimePeriod(models.Model):
    """
    >>> d = DataSet(name='test',objectType='Raster')
    >>> d1 = datetime(2006,12,07); d2 = datetime(2007,12,07)
    >>> t = TimePeriod(startDate=d1,endDate=d2,datasetID=d.id)
    
    >>> t = TimePeriod(date=d1,datasetID=d.id)

    """
    __module__ = 'duetopia.register.models'

    date = models.DateTimeField(null=True,blank=True, verbose_name=_('single date'))
    dtstart = ParsedDateField(null=True,blank=True, verbose_name=_('start date'))
    dtend = ParsedDateField(null=True,blank=True, verbose_name=_('end date'))
    #title = models.CharField(maxlength=255, blank=True, null=True, verbose_name=_('title'))    

    class Meta:
        verbose_name = _('temporal extents')
        verbose_name_plural = _('temporal extents')
    def __str__(self):
        if self.date:
            return str(self.date)
        else:    
            return str(self.dtstart)+' - '+str(self.dtend)

    class Admin:
        list_display = ('dtstart','dtend')
